// DynDlg.h
//

#ifndef __DYNDLG_H__
#define __DYNDLG_H__

// Macro returning the length of a resource string. 
#define _rcslen(lpcrsz)	wcslen(lpcrsz)

// Missing lstrcpyn() from Win32 API
#include <tchar.h>
#include <wchar.h>
//#define lstrcpyn	_tcsncpy

typedef HWND *	PHWND;

#define ARRAY_COUNT(a)		(sizeof(a) / sizeof((a)[0]))

// Ordinal scheme constant
#define RCH_ORDINAL_SCHEME	((WCHAR) -1)

/////////////////////////////////////////////////////////////////////////////
// Extended dialog templates (new in Win95)

#pragma pack(push, 1)

typedef struct
{
	WORD dlgVer;
	WORD signature;
	DWORD helpID;
	DWORD exStyle;
	DWORD style;
	WORD cDlgItems;
	short x;
	short y;
	short cx;
	short cy;
} DLGTEMPLATEEX;

typedef DLGTEMPLATEEX * LPDLGTEMPLATEEX;
typedef const DLGTEMPLATEEX * LPCDLGTEMPLATEEX;

typedef struct
{
	DWORD helpID;
	DWORD exStyle;
	DWORD style;
	short x;
	short y;
	short cx;
	short cy;
	DWORD id;
} DLGITEMTEMPLATEEX;

typedef DLGITEMTEMPLATEEX * LPDLGITEMTEMPLATEEX;
typedef const DLGITEMTEMPLATEEX * LPCDLGITEMTEMPLATEEX;

#pragma pack(pop)



// Dilaog menu template (vdmt)
/*
typedef union tagDLGMENUTEMPLATE
{
	struct
	{
		WCHAR	rchScheme;
		WORD	wOrd;
	} alt;
	WCHAR	szName[];
} DLGMENUTEMPLATE;

typedef DLGMENUTEMPLATE * LPDLGMENUTEMPLATE;
typedef const DLGMENUTEMPLATE * LPCDLGMENUTEMPLATE;
*/


// Dialog class template (vdct)
/*
typedef union tagDLGCLASSTEMPLATE
{
	struct
	{
		WCHAR	rchScheme;
		WORD	wAtom;
	} alt;
	WCHAR	szName[];
} DLGCLASSTEMPLATE;

typedef DLGCLASSTEMPLATE * LPDLGCLASSTEMPLATE;
typedef const DLGCLASSTEMPLATE * LPCDLGCLASSTEMPLATE;
*/

/*
// Dialog font template (vdft)
typedef struct tagDLGFONTTEMPLATE
{
	WORD	wSize;
	WCHAR	szName[];
} DLGFONTTEMPLATE;

typedef DLGFONTTEMPLATE * LPDLGFONTTEMPLATE;
typedef const DLGFONTTEMPLATE * LPCDLGFONTTEMPLATE;
*/
/*
// Dialog item class template (dict)
typedef union tagDLGITEMCLASSTEMPLATE
{
	struct
	{
		WCHAR	rchScheme;
		WCHAR	rchAtom;
	} alt;
	WCHAR	szName[];
} DLGITEMCLASSTEMPLATE;

typedef DLGITEMCLASSTEMPLATE * LPDLGITEMCLASSTEMPLATE;
typedef const DLGITEMCLASSTEMPLATE * LPCDLGITEMCLASSTEMPLATE;
*/

/*
// Dialog item title temaplte (ditt)
typedef union tagDLGITEMTITLETEMPLATE
{
	struct
	{
		WCHAR	rchScheme;
		WORD	wOrd;
	} alt;
	WCHAR	szTitle[];
} DLGITEMTITLETEMPLATE;
 
typedef DLGITEMTITLETEMPLATE * LPDLGITEMTITLETEMPLATE;
typedef const DLGITEMTITLETEMPLATE * LPCDLGITEMTITLETEMPLATE;
*/

/*
// Dialog item data template (didt)
typedef struct tagDLGITEMDATATEMPLATE
{
	WCHAR	rchSize;
	BYTE	bData[];
} DLGITEMDATATEMPLATE;  

typedef DLGITEMDATATEMPLATE * LPDLGITEMDATATEMPLATE;
typedef const DLGITEMDATATEMPLATE * LPCDLGITEMDATATEMPLATE;
*/

// ShowDlgCategory constants
#define SDC_SHOW	(TRUE)
#define SDC_HIDE	(FALSE)


// Dialog Box Section (dlgcat)
typedef struct tagDLGCATEGORY
{
	HINSTANCE		hinst;
//	LPCTSTR			lpcszTemplateName;
	int				nTemplateID;
	LPVOID			lpvData;

	// --- the following are used internally

	BOOL				bDialogEx;
	HGLOBAL				hglbTemplate;
	int					nItemCount;	
	LPDLGITEMTEMPLATE	lpditList;
	HLOCAL				hlocWndList;
} DLGCATEGORY;

typedef DLGCATEGORY * LPDLGCATEGORY;
typedef const DLGCATEGORY * LPCDLGCATEGORY;


	// Constants

#define DLGSEC_ERR		-1

	// Section category flags

#define DSCF_DISCARDABLE	0x0001
#define DSCF_PRELOAD		0x0002

	// Dialog section notification messages

#define DSN_LOADED		0x0001
#define DSN_DISCARDING		0x0002

	// Category wrapper structure (seccat)

typedef struct tagSECTIONCATEGORY
{
	int			nID;
	UINT		uFlags;
	DLGCATEGORY	dlgcat;
} SECTIONCATEGORY;

typedef SECTIONCATEGORY * LPSECTIONCATEGORY;
typedef const SECTIONCATEGORY * LPCSECTIONCATEGORY;

	// Dialog section structure (dlgsec)

typedef struct tagDLGSECTION
{
	int			nID;
//	HWND		hwndDlg;
	int			nFrameID;
	int			nCount;
	int			nLoaded;
	int			nMaxThreshold;
	int			nMinThreshold;
	int			nCurrentID;
	LPVOID		lpvData;
	LPSECTIONCATEGORY	lpseccatList;
} DLGSECTION; 

typedef DLGSECTION * LPDLGSECTION;
typedef const DLGSECTION * LPCDLGSECTION;



// Constants

#define CCH_MAX_CLASSNAME       80
#define CCH_MAX_TITLE           256

// Dialog item template variable information

typedef struct tagDLGITEMTEMPLATEVARINFO        // ditvi
{
	LPTSTR          lpszClassName;
	int             cchClassName;
	LPTSTR          lpszTitle;
	int             cchTitle;
	LPVOID          lpvData;
} DLGITEMTEMPLATEVARINFO;

typedef DLGITEMTEMPLATEVARINFO * LPDLGITEMTEMPLATEVARINFO;
typedef const DLGITEMTEMPLATEVARINFO * LPCDLGITEMTEMPLATEVARINFO;


#define BYTEPTRPLUS(lpv, n)             (((LPSTR) (lpv)) + (n))
#define AfterDlgResString(lpcsz)        ((lpcsz) + (wcslen(lpcsz)) + 1)
	

// Function implementations specific to the target environment

#define GetDlgItemTemplateExtStyle(lpdit)     (lpdit)->dwExtendedStyle


#endif // for __DYNDLG_H__